package core.model
{
import flash.errors.IllegalOperationError;
import flash.utils.Dictionary;

import framework.injection.DefaultInjectManager;

/**
 * GameModel
 * @author jliang
 * 
 */
public class GameModel
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function GameModel(enforce:SingletonEnforce)
	{
		if (enforce == null)
		{
			throw new IllegalOperationError("GameModel is a singleton class.");
		}
		_instance = this;
	}
	//==========================================================================
	//  Class constants
	//==========================================================================
	private static var _instance:GameModel;

	public static function get instance():GameModel
	{
		return _instance ? _instance : new GameModel(new SingletonEnforce());
	}
	//==========================================================================
	//  Properties
	//==========================================================================
    public var systemModel:SystemModel;
    
	public var playerModel:PlayerModel;
	
	public var mapModel:MapModel;
	
	public var questModel:QuestModel;
	
	public var friendModel:FriendModel;
	
	private var otherModels:Dictionary = new Dictionary(true);
    
    public function initialize():void
    {
        systemModel = new SystemModel();
        DefaultInjectManager.getInstace().addInjection("systemModel", systemModel);
        
		playerModel = new PlayerModel();
		DefaultInjectManager.getInstace().addInjection("playerModel", playerModel);
		
		mapModel = new MapModel();
		DefaultInjectManager.getInstace().addInjection("mapModel", mapModel);
		
		questModel = new QuestModel();
		DefaultInjectManager.getInstace().addInjection("questModel", questModel);
		
		friendModel = new FriendModel();
		DefaultInjectManager.getInstace().addInjection("friendModel", friendModel);
    }
	
	public function addModel(name:String, model:ModelBase):void
	{
		otherModels[name] = model;
	}
	
	public function removeModel(name:String):void
	{
		delete otherModels[name];
	}
	
	public function getModel(name:String):ModelBase
	{
		return otherModels[name];
	}
}
}

class SingletonEnforce
{
	
}